<?php
namespace app\index\controller;

use app\common\controller\Com;

class Auth extends Com
{
    public function _empty($name){
        return "无效操作：".$name;
    }


    public function initialize(){
        self::check_login();
    }


    //判断用户是否已经登陆
    final public function check_login() {
        $uid = is_user_login();
        if(!$uid)return $this->redirect('/com/login');
        define('UID',$uid);

        if(!config("common.auth_user_ondb_everytime"))return;

        $ainfo=model('user')->where('id','=',$uid)->field('state')->find();
        if(empty($ainfo) || 0==$ainfo['state']){
            $save_pre = config("common.user_login_save_pre");
            cookie($save_pre.'_auth', null);
            cookie($save_pre.'_auth_sign', null);
            session($save_pre.'_auth', null);
            session($save_pre.'_auth_sign', null);
            session($save_pre.'_rules',null);  //当前账号拥有的权限ids
            session($save_pre.'_author',null); //当前账号已验证的权限
            session('__forward__',null);

            return $this->redirect('/com/login');
        }
    }
}
